import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;


public class ServerTest {
       
int numberOfPlayers = 3;
int numberOfChips = 1000;
int smallBlind = 10;
int bigBlind = 2 * smallBlind;

        @Before
        public void setUp() throws Exception {
        }

        @After
        public void tearDown() throws Exception {
        }

        @Test(timeout=100)
        public void testnumericArrayToString() {        
               
                /* test metod odpowiadajacych konwersje kart graczy na ciag znakow zrozumialy dla
                   metody wybierajcej zwyciezce  */
               
                int port = 4442;
                numberOfPlayers = 2;
                Server server = new Server(port, numberOfPlayers, numberOfChips, smallBlind, bigBlind);
               
                String[][] tmp = new String[4][3];
                String card = "1-Red-Heart";
                tmp[0] = card.split("-");
               
                card = "6-Red-Diamond";
                tmp[1] = card.split("-");
               
                card = "3-Red-Diamond";
                tmp[2] = card.split("-");
               
                card = "2-Black-Spade";
                tmp[3] = card.split("-");
               
                assertEquals("xcba", server.encodeHand(server.organizeCards(tmp)));
               
               
               
                card = "10-Red-Diamond";
                tmp[0] = card.split("-");
               
                card = "11-Red-Diamond";
                tmp[1] = card.split("-");
               
                card = "12-Red-Diamond";
                tmp[2] = card.split("-");
               
                card = "13-Red-Diamond";
                tmp[3] = card.split("-");
               
                assertEquals("xxxj", server.encodeHand(server.organizeCards(tmp)));    
        }
       

        @Test(timeout=10000)
        public void testrun() throws InterruptedException {    
               
                //test metody pozwalajacej nowym graczom polaczyc sie do serwera
               
                int port = 4441;
                Server server = new Server(port, numberOfPlayers, numberOfChips, smallBlind, bigBlind);
               
                assertEquals(true, server.allowNewPlayers);
                new Bot("localhost", port);
               
                assertEquals(true, server.allowNewPlayers);
                new Bot("localhost", port);
               
                assertEquals(true, server.allowNewPlayers);
                new Bot("localhost", port);
               
                Thread.sleep(200);
                assertEquals(false, server.allowNewPlayers);
        }
       
       
        @Test(timeout=10)
        public void testallocateChips() {      
                int port = 4449;
                Server server = new Server(port, numberOfPlayers, numberOfChips, smallBlind, bigBlind);
               
                server.allocateChips(numberOfPlayers, numberOfChips);
                assertEquals(numberOfChips , server.playerChips[0]);
                assertEquals(numberOfChips , server.playerChips[1]);
                assertEquals(numberOfChips , server.playerChips[2]);            
        }
       
       
        @Test(timeout=10)
        public void testsetPlayerStatus() {    
                int port = 4450;
                Server server = new Server(port, numberOfPlayers, numberOfChips, smallBlind, bigBlind);
               
                server.setPlayersStatus(numberOfPlayers);
                assertEquals(false, server.playerStatus[0]);
                assertEquals(false, server.playerStatus[1]);
                assertEquals(false, server.playerStatus[2]);            
        }
       
       
        @Test(timeout=100)
        public void testsliceAllNulls() {
               
                int port = 4451;
                Server server = new Server(port, numberOfPlayers, numberOfChips, smallBlind, bigBlind);
                       
                server.currentDeck[15] = null;
                assertEquals(null, server.currentDeck[15]);
               
                server.sliceAllNulls(server.currentDeck);

                assertNotNull(server.currentDeck[15]);
        }
       
       
       
        @Test(timeout=100)
        public void testNewDeckOfCards() {
               
                //Sprawdzenie kilku skrajnych przypadkow w celu weryfikacji poprawnosci dzialania metody
                       
                int port = 4452;
                Server server = new Server(port, numberOfPlayers, numberOfChips, smallBlind, bigBlind);
               
                String currentDeck[] = server.newDeckOfCards();
               
               
                assertEquals("1-Red-Heart", currentDeck[0]);
                assertEquals("3-Black-Spade", currentDeck[10]);
                assertEquals("5-Red-Diamond", currentDeck[17]);
                assertEquals("13-Black-Club", currentDeck[51]);
               
               
        }
}
